<% 
Function fc_i_emailcheck(str_email)
	fc_i_emailcheck = fc_i_emailcheck_internal(str_email, -1)
End Function

Function fc_i_mk_user_pw_inquiry(lng_k_User_Id) ''Awaiting for Session("ses_iu") like value
	fc_i_mk_user_pw_inquery = fc_i_emailcheck_internal("", lng_k_User_Id)
End Function

'******************************************************************************
'überprüpft in wie vielen profilen es eine emailadresse gibt
'und trägt die Infos in eine tabelle ein
'******************************************************************************
Function fc_i_emailcheck_internal(str_email, lng_k_User_Id)
Dim objRS_tmp
Dim sql_tmp
Dim i_found

i_found = 0'default
Dim i_found_sum
i_found_sum = 0'default

'nur für den Test
'sql_tmp = "DELETE FROM tbl_0903_pw_inquiry"
'objConn.Execute sql_tmp
Dim lng_k_email_inquiry
Dim nID
'tbl_0903_pw_inquiry
'generiert eine eindeutige ID für diese Anfrage
Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
sql_tmp = "SELECT max(lng_k_email_inquiry) AS nID FROM tbl_0903_pw_inquiry"
objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockOptimistic 
'Speichern der ID in eine Variable
nID = objRS_tmp.Fields("nID")
If IsNull(nID) or IsEmpty(nID) Then
	nID = 1
end if

objRS_tmp.close
set objRS_tmp = nothing

If nID > 0 Then
	lng_k_email_inquiry = nID + 1
end if

Dim str_log_id
Dim str_master_id
Dim lng_fk_head_organization
Dim lng_fk_organization
Dim lng_fk_trainer
Dim lng_fk_athlete
Dim lng_fk_User_ID
Dim i_type
Dim str_info
Dim str_User_id
Dim str_pw

Dim i_count

'str_info = "Typ A - Admin"
'legt jetzt einen Datensatz an damit diese ID geschützt ist
'sql_tmp = "INSERT INTO tbl_0903_pw_inquiry " & _
' "(" & _
'	  " lng_k_email_inquiry" & _
'	  ", str_email" & _
'	  ", str_log_id" & _
'	  ", str_master_id" & _
'	  ", lng_fk_head_organization" & _
'	  ", lng_fk_organization" & _
'	  ", lng_fk_trainer" & _
'	  ", lng_fk_athlete" & _
'	  ", lng_fk_User_ID" & _
'	  ", i_type" & _
'	  ", str_info" & _
'	  ", str_User_id" & _
'	  ", str_pw" & _
'  ") VALUES ('" & lng_k_email_inquiry & "'" & _
'		", '" & str_email & "'" & _
'		", '" & str_log_id & "'" & _
'		", '" & str_master_id & "'" & _
'		", '" & lng_fk_head_organization & "'" & _
'		", '" & lng_fk_organization & "'" & _
'		", '" & lng_fk_trainer & "'" & _
'		", '" & lng_fk_athlete & "'" & _
'		", '" & lng_fk_User_ID & "'" & _
'		", '" & i_type & "'" & _
'		", '" & str_info & "'" & _
'		", '" & str_User_id & "'" & _
'		", '" & str_pw & "'" & _
' ")"
' 
''Response.Write("sql_tmp: " & sql_tmp & "<br>")

'Response.Write("lng_k_email_inquiry: " & lng_k_email_inquiry & "<br>")
	
If ( lng_k_User_Id = -1 ) Then
		
	'Typ A Admin ------------------------------------------------------------------
	sql_tmp = "SELECT tbl_0190_head_organization.str_business_email_ow, tbl_0190_head_organization.str_business_email_02_ow, " & _
	"tbl_0101_master_id.str_master_id, tbl_0101_master_id.lng_fk_organization, tbl_0101_master_id.lng_fk_trainer, " & _
	"tbl_0101_master_id.lng_fk_athlete, tbl_0101_master_id.lng_fk_User_ID, tbl_0101_master_id.str_log_id, tbl_0101_master_id.i_type, " & _
	"tbl_0190_head_organization.lng_k_head_organization, tbl_0501_user.str_User_id, tbl_0501_user.str_pw " & _
	"FROM tbl_0190_head_organization " & _
	"Inner Join tbl_0101_master_id ON tbl_0101_master_id.lng_fk_head_organization = tbl_0190_head_organization.lng_k_head_organization " & _
	"Inner Join tbl_0501_user ON tbl_0501_user.lng_k_User_ID = tbl_0101_master_id.lng_fk_User_ID "
	
	If ( lng_k_User_Id = -1 ) Then
		sql_tmp = sql_tmp & " WHERE tbl_0190_head_organization.str_business_email_ow = '" & str_email & "' " & _
							"OR tbl_0190_head_organization.str_business_email_02_ow = '" & str_email & "'"
	Else
		sql_tmp = sql_tmp & " WHERE tbl_0501_user.lng_k_User_ID = '" & lng_k_User_Id & "' "
	End If
	
	'Response.Write("sql_tmp2: " & sql_tmp & "<br>")
		
	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  

	Do While Not objRS_tmp.EOF
		
		i_found = i_found + 1
		str_log_id = objRS_tmp.Fields("str_log_id").value
		str_master_id = objRS_tmp.Fields("str_master_id").value
		lng_fk_head_organization = objRS_tmp.Fields("lng_k_head_organization").value
		lng_fk_organization = 0
		lng_fk_trainer = 0
		lng_fk_athlete = 0
		lng_fk_User_ID = objRS_tmp.Fields("lng_fk_User_ID").value
		i_type = objRS_tmp.Fields("i_type").value
		str_User_id = objRS_tmp.Fields("str_User_id").value
		str_pw = objRS_tmp.Fields("str_pw").value
		str_info = "Typ A - Admin"
		
		If ( lng_k_User_Id <> -1 ) Then
			str_email = objRS_tmp.Fields("str_business_email_ow").value
		End If
		
		'legt jetzt einen Datensatz an damit dieseR ID AN
		sql_tmp = "INSERT INTO tbl_0903_pw_inquiry " & _
		 "(" & _
			  " lng_k_email_inquiry" & _
			  ", str_email" & _
			  ", str_log_id" & _
			  ", str_master_id" & _
			  ", lng_fk_head_organization" & _
			  ", lng_fk_organization" & _
			  ", lng_fk_trainer" & _
			  ", lng_fk_athlete" & _
			  ", lng_fk_User_ID" & _
			  ", i_type" & _
			  ", str_info" & _
			  ", str_User_id" & _
			  ", str_pw" & _
		  ") VALUES ('" & lng_k_email_inquiry & "'" & _
				", '" & str_email & "'" & _
				", '" & str_log_id & "'" & _
				", '" & str_master_id & "'" & _
				", '" & lng_fk_head_organization & "'" & _
				", '" & lng_fk_organization & "'" & _
				", '" & lng_fk_trainer & "'" & _
				", '" & lng_fk_athlete & "'" & _
				", '" & lng_fk_User_ID & "'" & _
				", '" & i_type & "'" & _
				", '" & str_info & "'" & _
				", '" & str_User_id & "'" & _
				", '" & str_pw & "'" & _
		 ")"
		 
		objConn.Execute sql_tmp
	
	objRS_tmp.MoveNext
	Loop
	
	objRS_tmp.Close
	Set objRS_tmp = Nothing
	
		
	'Typ A Division oder B Admin ------------------------------------------------------------------
	sql_tmp = "SELECT tbl_0101_master_id.str_master_id, tbl_0101_master_id.lng_fk_organization, tbl_0101_master_id.lng_fk_trainer, " & _
	"tbl_0101_master_id.lng_fk_athlete, tbl_0101_master_id.lng_fk_User_ID, tbl_0101_master_id.i_type, tbl_0101_master_id.str_log_id, " & _
	"tbl_0501_user.str_User_id, tbl_0501_user.str_pw, tbl_0201_organization.lng_k_organization, tbl_0201_organization.lng_fk_head_organization, " & _
	"tbl_0201_organization.str_email_ac, tbl_0201_organization.str_email_02_ac " & _
	"FROM tbl_0101_master_id " & _
	"Inner Join tbl_0501_user ON tbl_0501_user.lng_k_User_ID = tbl_0101_master_id.lng_fk_User_ID " & _
	"Inner Join tbl_0201_organization ON tbl_0201_organization.lng_k_organization = tbl_0101_master_id.lng_fk_organization "
	
	If ( lng_k_User_Id = -1 ) Then
		sql_tmp = sql_tmp & " WHERE tbl_0201_organization.str_email_ac = '" & str_email & "' " & _
							"OR tbl_0201_organization.str_email_02_ac = '" & str_email & "' "
	Else
		sql_tmp = sql_tmp & " WHERE tbl_0101_master_id.lng_fk_User_ID = '" & lng_k_User_Id & "' "
	End If
	
	'Response.Write("sql_tmp3: " & sql_tmp & "<br>")
		
	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  

	Do While Not objRS_tmp.EOF
		
		i_found = i_found + 1
		str_log_id = objRS_tmp.Fields("str_log_id").value
		str_master_id = objRS_tmp.Fields("str_master_id").value
		lng_fk_head_organization = objRS_tmp.Fields("lng_fk_head_organization").value
		lng_fk_organization = objRS_tmp.Fields("lng_k_organization").value
		lng_fk_trainer = 0
		lng_fk_athlete = 0
		lng_fk_User_ID = objRS_tmp.Fields("lng_fk_User_ID").value
		i_type = objRS_tmp.Fields("i_type").value
		str_User_id = objRS_tmp.Fields("str_User_id").value
		str_pw = objRS_tmp.Fields("str_pw").value
		
		If lng_fk_head_organization > 1 Then
			str_info = "Typ A - Division Admin"
		end if
		If lng_fk_head_organization = 1 Then
			str_info = "Typ B - Admin"
		end if
		
		If ( lng_k_User_Id <> -1 ) Then
			str_email = objRS_tmp.Fields("str_email_ac").value
		End If

		'legt jetzt einen Datensatz an damit dieseR ID AN
		sql_tmp = "INSERT INTO tbl_0903_pw_inquiry " & _
		 "(" & _
			  " lng_k_email_inquiry" & _
			  ", str_email" & _
			  ", str_log_id" & _
			  ", str_master_id" & _
			  ", lng_fk_head_organization" & _
			  ", lng_fk_organization" & _
			  ", lng_fk_trainer" & _
			  ", lng_fk_athlete" & _
			  ", lng_fk_User_ID" & _
			  ", i_type" & _
			  ", str_info" & _
			  ", str_User_id" & _
			  ", str_pw" & _
		  ") VALUES ('" & lng_k_email_inquiry & "'" & _
				", '" & str_email & "'" & _
				", '" & str_log_id & "'" & _
				", '" & str_master_id & "'" & _
				", '" & lng_fk_head_organization & "'" & _
				", '" & lng_fk_organization & "'" & _
				", '" & lng_fk_trainer & "'" & _
				", '" & lng_fk_athlete & "'" & _
				", '" & lng_fk_User_ID & "'" & _
				", '" & i_type & "'" & _
				", '" & str_info & "'" & _
				", '" & str_User_id & "'" & _
				", '" & str_pw & "'" & _
		 ")"
		 
		objConn.Execute sql_tmp
	
	objRS_tmp.MoveNext
	Loop
	
	objRS_tmp.Close
	Set objRS_tmp = Nothing	
	
		
	'Typ A Trainer / Typ B Trainer Typ C Admin------------------------------------------------------------------
	sql_tmp = "SELECT tbl_0101_master_id.str_master_id, tbl_0101_master_id.lng_fk_trainer, tbl_0101_master_id.lng_fk_athlete, " & _
	"tbl_0101_master_id.lng_fk_User_ID, tbl_0101_master_id.i_type, tbl_0501_user.str_User_id, tbl_0501_user.str_pw, " & _
	"tbl_0101_master_id.str_log_id, tbl_0301_trainer.str_email_ac, tbl_0301_trainer.str_email_02_ac, " & _
	"tbl_0301_trainer.lng_k_trainer, tbl_0201_organization.lng_k_organization, tbl_0201_organization.lng_fk_head_organization " & _
	"FROM tbl_0101_master_id " & _
	"Inner Join tbl_0501_user ON tbl_0501_user.lng_k_User_ID = tbl_0101_master_id.lng_fk_User_ID " & _
	"Inner Join tbl_0301_trainer ON tbl_0301_trainer.lng_k_trainer = tbl_0101_master_id.lng_fk_trainer " & _
	"Left Join tbl_0201_organization ON tbl_0201_organization.lng_k_organization = tbl_0301_trainer.lng_fk_organization "
	
	If ( lng_k_User_Id = -1 ) Then
		sql_tmp = sql_tmp & " WHERE tbl_0301_trainer.str_email_ac = '" & str_email & "' " & _
							"OR tbl_0301_trainer.str_email_02_ac = '" & str_email & "' "
	
	Else
		sql_tmp = sql_tmp & " WHERE tbl_0101_master_id.lng_fk_User_ID = '" & lng_k_User_Id & "' "
	End If
	
	'Response.Write("sql_tmp3: " & sql_tmp & "<br>")
	
	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  

	Do While Not objRS_tmp.EOF
		
		i_found = i_found + 1
		str_log_id = objRS_tmp.Fields("str_log_id").value
		str_master_id = objRS_tmp.Fields("str_master_id").value
		lng_fk_head_organization = objRS_tmp.Fields("lng_fk_head_organization").value
		lng_fk_organization = objRS_tmp.Fields("lng_k_organization").value
		lng_fk_trainer = objRS_tmp.Fields("lng_k_trainer").value
		lng_fk_athlete = 0
		lng_fk_User_ID = objRS_tmp.Fields("lng_fk_User_ID").value
		i_type = objRS_tmp.Fields("i_type").value
		str_User_id = objRS_tmp.Fields("str_User_id").value
		str_pw = objRS_tmp.Fields("str_pw").value
		
		If lng_fk_head_organization > 1 AND lng_fk_organization > 1 Then
			str_info = "Typ A - Trainer Admin"
		end if
		If lng_fk_head_organization = 1 AND lng_fk_organization > 1 Then
			str_info = "Typ B - Trainer Admin"
		end if
		If lng_fk_head_organization = 1 AND lng_fk_organization = 1 Then
			str_info = "Typ C - Admin"
		end if
		
		If ( lng_k_User_Id <> -1 ) Then
			str_email = objRS_tmp.Fields("str_email_ac").value
		End If

		'legt jetzt einen Datensatz an damit dieseR ID AN
		sql_tmp = "INSERT INTO tbl_0903_pw_inquiry " & _
		 "(" & _
			  " lng_k_email_inquiry" & _
			  ", str_email" & _
			  ", str_log_id" & _
			  ", str_master_id" & _
			  ", lng_fk_head_organization" & _
			  ", lng_fk_organization" & _
			  ", lng_fk_trainer" & _
			  ", lng_fk_athlete" & _
			  ", lng_fk_User_ID" & _
			  ", i_type" & _
			  ", str_info" & _
			  ", str_User_id" & _
			  ", str_pw" & _
		  ") VALUES ('" & lng_k_email_inquiry & "'" & _
				", '" & str_email & "'" & _
				", '" & str_log_id & "'" & _
				", '" & str_master_id & "'" & _
				", '" & lng_fk_head_organization & "'" & _
				", '" & lng_fk_organization & "'" & _
				", '" & lng_fk_trainer & "'" & _
				", '" & lng_fk_athlete & "'" & _
				", '" & lng_fk_User_ID & "'" & _
				", '" & i_type & "'" & _
				", '" & str_info & "'" & _
				", '" & str_User_id & "'" & _
				", '" & str_pw & "'" & _
		 ")"
		 
		objConn.Execute sql_tmp
	
	objRS_tmp.MoveNext
	Loop
	
	objRS_tmp.Close
	Set objRS_tmp = Nothing	

End If	
'Typ A-B-C Athlete ------------------------------------------------------------------
sql_tmp = "SELECT tbl_0101_master_id.str_master_id, tbl_0101_master_id.lng_fk_athlete, tbl_0101_master_id.lng_fk_User_ID, " & _
"tbl_0101_master_id.i_type, tbl_0501_user.str_User_id, tbl_0501_user.str_pw, tbl_0101_master_id.str_log_id, tbl_0401_athlete.lng_k_athlete, " & _
"tbl_0401_athlete.lng_fk_trainer, tbl_0301_trainer.lng_fk_organization, tbl_0201_organization.lng_fk_head_organization, tbl_0501_user.str_User_email " & _
"FROM tbl_0101_master_id " & _
"Inner Join tbl_0501_user ON tbl_0501_user.lng_k_User_ID = tbl_0101_master_id.lng_fk_User_ID " & _
"Inner Join tbl_0401_athlete ON tbl_0101_master_id.lng_fk_athlete = tbl_0401_athlete.lng_k_athlete " & _
"Left Join tbl_0301_trainer ON tbl_0301_trainer.lng_k_trainer = tbl_0401_athlete.lng_fk_trainer " & _
"Left Join tbl_0201_organization ON tbl_0301_trainer.lng_fk_organization = tbl_0201_organization.lng_k_organization "

If ( lng_k_User_Id = -1 ) Then
	sql_tmp = sql_tmp & " WHERE tbl_0501_user.str_User_email = '" & str_email & "' " & _
						"OR tbl_0501_user.str_User_email_02 = '" & str_email & "' "

Else
	sql_tmp = sql_tmp & " WHERE tbl_0101_master_id.lng_fk_User_ID = '" & lng_k_User_Id & "' "
End If


'Response.Write("sql_tmp3: " & sql_tmp & "<br>")
	
	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  

	Do While Not objRS_tmp.EOF
		
		i_found = i_found + 1
		str_log_id = objRS_tmp.Fields("str_log_id").value
		str_master_id = objRS_tmp.Fields("str_master_id").value
		lng_fk_head_organization = objRS_tmp.Fields("lng_fk_head_organization").value
		lng_fk_organization = objRS_tmp.Fields("lng_fk_organization").value
		lng_fk_trainer = objRS_tmp.Fields("lng_fk_trainer").value
		lng_fk_athlete = objRS_tmp.Fields("lng_k_athlete").value
		lng_fk_User_ID = objRS_tmp.Fields("lng_fk_User_ID").value
		i_type = objRS_tmp.Fields("i_type").value
		str_User_id = objRS_tmp.Fields("str_User_id").value
		str_pw = objRS_tmp.Fields("str_pw").value
		
		If lng_fk_head_organization > 1 AND lng_fk_organization > 1 Then
			str_info = "Typ A - Athlete"
		end if
		If lng_fk_head_organization = 1 AND lng_fk_organization > 1 Then
			str_info = "Typ B - Athlete"
		end if
		If lng_fk_head_organization = 1 AND lng_fk_organization = 1 Then
			str_info = "Typ C - Athlete"
		end if

		If ( lng_k_User_Id <> -1 ) Then
			str_email = objRS_tmp.Fields("str_User_email").value
		End If

		'legt jetzt einen Datensatz an damit dieseR ID AN
		sql_tmp = "INSERT INTO tbl_0903_pw_inquiry " & _
		 "(" & _
			  " lng_k_email_inquiry" & _
			  ", str_email" & _
			  ", str_log_id" & _
			  ", str_master_id" & _
			  ", lng_fk_head_organization" & _
			  ", lng_fk_organization" & _
			  ", lng_fk_trainer" & _
			  ", lng_fk_athlete" & _
			  ", lng_fk_User_ID" & _
			  ", i_type" & _
			  ", str_info" & _
			  ", str_User_id" & _
			  ", str_pw" & _
		  ") VALUES ('" & lng_k_email_inquiry & "'" & _
				", '" & str_email & "'" & _
				", '" & str_log_id & "'" & _
				", '" & str_master_id & "'" & _
				", '" & lng_fk_head_organization & "'" & _
				", '" & lng_fk_organization & "'" & _
				", '" & lng_fk_trainer & "'" & _
				", '" & lng_fk_athlete & "'" & _
				", '" & lng_fk_User_ID & "'" & _
				", '" & i_type & "'" & _
				", '" & str_info & "'" & _
				", '" & str_User_id & "'" & _
				", '" & str_pw & "'" & _
		 ")"
		 
		objConn.Execute sql_tmp
	
	objRS_tmp.MoveNext
	Loop
	
	objRS_tmp.Close
	Set objRS_tmp = Nothing		

'---------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
'Jetzt wird überprüft ob es überhaupt einen treffen gegeben hat
If ( lng_k_User_Id = -1 ) Then
	sql_tmp = "SELECT COUNT(1) AS i_count FROM tbl_0903_pw_inquiry WHERE lng_k_email_inquiry = '" & lng_k_email_inquiry & "'"
Else
	sql_tmp = "SELECT COUNT(1) AS i_count FROM tbl_0903_pw_inquiry WHERE lng_fk_User_ID = '" & lng_k_User_Id & "'"
End If
'Response.Write("sql_tmp: " & sql_tmp & "<br>")

Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  

	i_count = objRS_tmp.Fields("i_count")
	
objRS_tmp.Close
Set objRS_tmp = Nothing	

if IsNull(i_count) or IsEmpty(i_count) Then
	i_count = 0
end if
'---------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
If Cint(i_count) > 0 Then
	fc_i_emailcheck_internal = lng_k_email_inquiry
else
	fc_i_emailcheck_internal = 0
end if

End Function
'******************************************************************************
'überprpft in wie vielen profilen es eine emailadresse gibt Version 01
'******************************************************************************
Function fc_i_emailcheck_v01(str_email)

Dim objRS_tmp
Dim sql_tmp
Dim i_found

i_found = 0'default
	
'Typ A Admin ------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0190_head_organization WHERE " & _
"str_business_email_ow = '" & str_email & "' " & _
"OR str_business_email_02_ow = '" & str_email & "' "

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = Cint(objRS_tmp.Fields("i_found"))
	objRS_tmp.Close
	Set objRS_tmp = Nothing
	
'Typ A Division ------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0201_organization WHERE " & _
"str_email_ac = '" & str_email & "' " & _
"And lng_fk_head_organization >'1' " & _ 
"OR str_email_02_ac = '" & str_email & "' " & _ 
"And lng_fk_head_organization >'1'"

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = i_found + (Cint(objRS_tmp.Fields("i_found")))
	objRS_tmp.Close
	Set objRS_tmp = Nothing
	
'Typ A Trainer ------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0301_trainer " & _
"Inner Join tbl_0201_organization ON tbl_0201_organization.lng_k_organization = tbl_0301_trainer.lng_fk_organization " & _
"Inner Join tbl_0190_head_organization ON tbl_0190_head_organization.lng_k_head_organization = tbl_0201_organization.lng_fk_head_organization " & _
"WHERE " & _
"tbl_0301_trainer.str_email_ac = '" & str_email & "' " & _
"And tbl_0190_head_organization.lng_k_head_organization >'1' " & _ 
"OR tbl_0301_trainer.str_email_02_ac = '" & str_email & "' " & _ 
"And tbl_0190_head_organization.lng_k_head_organization >'1'"

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = i_found + (Cint(objRS_tmp.Fields("i_found")))
	objRS_tmp.Close
	Set objRS_tmp = Nothing
	
'Typ A-B-C Athlete ------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0501_user WHERE " & _
"str_User_email = '" & str_email & "' " & _
"AND lng_fk_user_group = '" & 5 & "' " & _
"OR str_User_email = '" & str_email & "' " & _
"AND lng_fk_user_group = '" & 5 & "' "

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = i_found + (Cint(objRS_tmp.Fields("i_found")))
	objRS_tmp.Close
	Set objRS_tmp = Nothing
	
'---------------------------------------------------------------------------------
'Typ B Admin ---------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0201_organization WHERE " & _
"str_email_ac = '" & str_email & "' " & _
"And lng_fk_head_organization ='1' " & _ 
"OR str_email_02_ac = '" & str_email & "' " & _ 
"And lng_fk_head_organization ='1'"

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = i_found + (Cint(objRS_tmp.Fields("i_found")))
	objRS_tmp.Close
	Set objRS_tmp = Nothing

'Typ B Trainer ------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0301_trainer " & _
"Inner Join tbl_0201_organization ON tbl_0201_organization.lng_k_organization = tbl_0301_trainer.lng_fk_organization " & _
"Inner Join tbl_0190_head_organization ON tbl_0190_head_organization.lng_k_head_organization = tbl_0201_organization.lng_fk_head_organization " & _
"WHERE " & _
"tbl_0301_trainer.str_email_ac = '" & str_email & "' " & _
"And tbl_0190_head_organization.lng_k_head_organization ='1' " & _ 
"And tbl_0201_organization.lng_k_organization >'1' " & _ 
"OR tbl_0301_trainer.str_email_02_ac = '" & str_email & "' " & _ 
"And tbl_0190_head_organization.lng_k_head_organization ='1'" & _ 
"And tbl_0201_organization.lng_k_organization >'1' "

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = i_found + (Cint(objRS_tmp.Fields("i_found")))
	objRS_tmp.Close
	Set objRS_tmp = Nothing

'---------------------------------------------------------------------------------
'Typ C Admin ------------------------------------------------------------------
sql_tmp = "SELECT COUNT(1) AS i_found " & _
"FROM tbl_0301_trainer WHERE " & _
"str_email_ac = '" & str_email & "' " & _
"And lng_fk_organization ='1' " & _ 
"OR str_email_02_ac = '" & str_email & "' " & _ 
"And lng_fk_organization ='1'"

'Response.Write(sql_tmp)	
'response.End()

	Set objRS_tmp = Server.CreateObject("ADODB.Recordset")
	objRS_tmp.Open sql_tmp, objConn, adOpenStatic, adLockReadOnly  
		i_found = i_found + (Cint(objRS_tmp.Fields("i_found")))
	objRS_tmp.Close
	Set objRS_tmp = Nothing

'---------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
fc_i_emailcheck_v01 = i_found

End Function

%>
